package com.qiaoyanqing.ximalaya.discovermodule.discover_fragment;


import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_adapter.DiscoverAlbumShowLVadapter;
import com.qiaoyanqing.ximalaya.discovermodule.discover_callback.DiscoverAlbumShowService;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.DiscoverAlbumShowEntity;
import com.qiaoyanqing.ximalaya.url.Urlconfig;
import com.qiaoyanqing.ximalaya.util.MyLog;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class AlbumShowFragment extends Fragment {
    private ListView malbumshowlistview;
    private List<DiscoverAlbumShowEntity.DataBean.TracksBean.ListBean>mData=new ArrayList<>();
    private DiscoverAlbumShowLVadapter mLVadapter;
    private  MediaPlayer player=new MediaPlayer();




    public AlbumShowFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_album_show, container, false);

        malbumshowlistview= (ListView) view.findViewById(R.id.albumshowlistview);

        initData();



        return view;
    }


    private void initData() {
        long albumid=getActivity().getIntent().getIntExtra("album",4427085);
        MyLog.i("flag","------albumid"+albumid);
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Urlconfig.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        DiscoverAlbumShowService service=retrofit.create(DiscoverAlbumShowService.class);
        service.getshow(albumid).enqueue(new Callback<DiscoverAlbumShowEntity>() {
            @Override
            public void onResponse(Call<DiscoverAlbumShowEntity> call, final Response<DiscoverAlbumShowEntity> response) {
                MyLog.i("flag","------response"+response.body().getData().getTracks().getList().get(1).getTitle());
                //      MyLog.i("flag","------respnse"+);
                mData.addAll(response.body().getData().getTracks().getList());


                mLVadapter=new DiscoverAlbumShowLVadapter(response.body().getData().getTracks().getList(),getContext());

                mLVadapter.notifyDataSetChanged();
                malbumshowlistview.setAdapter(mLVadapter);



            }

            @Override
            public void onFailure(Call<DiscoverAlbumShowEntity> call, Throwable t) {

            }
        });



    }

}
